#ifndef BOOKMARKDIALOG_H
#define BOOKMARKDIALOG_H

#include <QDialog>
#include "bookmarkmanager.h"

class QTreeWidget;
class QPushButton;
class QLineEdit;
class QTextEdit;
class QDialogButtonBox;

class BookmarkDialog : public QDialog
{
    Q_OBJECT

public:
    explicit BookmarkDialog(BookmarkManager *manager, const QString &currentQuery = QString(), 
                           const QString &currentDatabase = QString(), QWidget *parent = nullptr);
    
signals:
    void querySelected(const QString &query);

private slots:
    void loadBookmarks();
    void searchBookmarks();
    void addBookmark();
    void editBookmark();
    void removeBookmark();
    void onItemDoubleClicked();
    void onItemSelected();
    void useSelectedQuery();
    void clearAllBookmarks();

private:
    void setupUI();
    void updateBookmarkList(const QList<BookmarkItem> &items);
    void resetForm();
    
    BookmarkManager *m_bookmarkManager;
    QTreeWidget *m_bookmarkTree;
    QPushButton *m_useButton;
    QPushButton *m_editButton;
    QPushButton *m_removeButton;
    QPushButton *m_clearButton;
    QLineEdit *m_searchEdit;
    QLineEdit *m_nameEdit;
    QTextEdit *m_queryEdit;
    QDialogButtonBox *m_buttonBox;
    
    QString m_currentDatabase;
    QString m_selectedQuery;
    int m_selectedBookmarkId;
    bool m_editMode;
};

#endif // BOOKMARKDIALOG_H